package com.finger.hospservice.controller;

import com.finger.hospservice.service.DictService;
import com.finger.modelservice.model.cmn.Dict;
import com.finger.modelservice.result.Result;
import org.bson.types.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/admin/hosp/dict")
public class DictController {

    @Autowired
    private DictService dictService;

    // 根据id查找下层的数据字典
    @GetMapping("/findDict/{id}")
    public Result findDict(@PathVariable Long id){

        List<Dict> dictList = dictService.findDict(id);

        return Result.ok(dictList);
    }

    // 下载数据字典
    @GetMapping("/downLoadDict")
    public void uploadDict(HttpServletResponse response){
        dictService.downLoadDict(response);
    }

    // 上传excel格式的 数据字典
    @PostMapping("/uploadDict")
    public Result uploadDict(MultipartFile file){
        dictService.uploadDict(file);
        return Result.ok();
    }

    @GetMapping("findDictByCode/{code}")
    public Result findDictByCode(@PathVariable String code){
        List<Dict> list = dictService.findDictByCode(code);
        Result<List<Dict>> ok = Result.ok(list);
        return ok;
    }

    @GetMapping("getName/{value}")
    public String getName(@RequestParam("value")String value){

        return dictService.getName("",value);
    }

    @GetMapping("getName/{code}/{value}")
    public String getName(@RequestParam("code")String code,
                          @RequestParam("value")String value){

        return dictService.getName(code,value);
    }

}
